#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;


//队列+BFS01：N叉树的层序遍历
class Solution1 {
    class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
public:
    vector<vector<int>> levelOrder(Node* root) 
    {
        if(root==nullptr)   
            return {};
        vector<vector<int>> ret;
        queue<Node*>  bfs({root});
        while(!bfs.empty())
        {
            int size=bfs.size();
            vector<int> temp;
            for(int i=0;i<size;i++)
            {
                if(!bfs.front()->children.empty())
                {
                    for(int j=0;j<bfs.front()->children.size();j++)
                    {
                        bfs.push(bfs.front()->children[j]);
                    }
                }
                temp.push_back(bfs.front()->val);
                bfs.pop();
            }
            ret.push_back(temp);
        }
        return ret;    
    }
};




//队列+BFS02：二叉树的锯齿形层序遍历
class Solution {
    struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode() : val(0), left(nullptr), right(nullptr) {}
     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
 right(right) {}
 };
public:
    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
        if (root == nullptr)
            return {};
        vector<vector<int>> ret;
        queue<TreeNode*> bfs({root});
        int path = 0; // 0表示正向遍历，1表示逆向遍历
        while (!bfs.empty()) {
            int size = bfs.size();
            vector<int> tmp;
            // vector<TreeNode*> storey;
            for (int i = 0; i < size; i++) {
                if (bfs.front()->left)
                    bfs.push(bfs.front()->left);
                if (bfs.front()->right)
                    bfs.push(bfs.front()->right);
                tmp.push_back(bfs.front()->val);
                bfs.pop();
            }
            if (path == 0) {
                ret.emplace_back(tmp);
                path = 1;
            } else {
                path = 0;
                ret.emplace_back(vector<int>(tmp.rbegin(), tmp.rend()));
            }
        }
        return ret;
    }
};

int func(int a,int b)
{
    return a+b;
}


void test1(int(*func)(int,int))
{
    int a=5;int b=3;
    cout<<func(a,b)<<endl;
    return;
}


int main()
{
    //function
    int(*func_ptr)(int,int)=func;
    test1(func_ptr);
    return 0;
}